import getopt, sys
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hi:ov", ["help", "input=", "output=", "version="])
    except getopt.GetoptError:
        # print help information and exit:
        usage()
        sys.exit(2)
    inputFile = ""
    outputFile = ""
    verbose = False
    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            #sys.exit()
        if o in ("-i", "--input"):
            inputFile = a            
        if o in ("-o", "--output"):
            outputFile = a            
        if o == "-v":
            verbose = True
            usage()
            sys.exit()
        if o == "--version":
            verbose = True
            showVersion()
            sys.exit()
    # ...
    
    print "----inputFile=" + inputFile
    print "----output=" + outputFile
    
    for o in args:
        print "----args=" + o
    
    file_object = open(inputFile+'.txt')
    try:
        all_the_text = file_object.read( )
    finally:
        file_object.close( )
        
    doProcess(inputFile, all_the_text)
    sys.exit()
    


def usage():
    print "----in usage"


def showVersion():
    usage()
    print "----in showVersion"
	
def doProcess(inputFile, all_the_text):
    if (inputFile == "1"):
        doSub1(all_the_text)
    elif (inputFile == "2"):
    	doSub2(all_the_text)
    elif (inputFile == "3"):
    	doSub3(all_the_text)
    elif (inputFile == "4"):
    	doSub4(all_the_text)
    elif (inputFile == "5"):
    	doSub5(all_the_text)
    elif (inputFile == "6"):
    	doSub6(all_the_text)
    elif (inputFile == "7"):
    	doSub7(all_the_text)
    elif (inputFile == "8"):
    	doSub8(all_the_text)

def doSub1(all_the_text):
    print "----in doSub1()"
    for i in range(1,2):
        for j in range(1,2):
            p = all_the_text
            p = p.replace('#1#',str(i))
            p = p.replace('#2#',str(j))
            p = p.replace('#3#',str(i*10+j))
            print p

def doSub2(all_the_text):
    print "----in doSub2()"
    for i in range(1,2):
        for j in range(1,2):
            p = all_the_text
            p = p.replace('#1#',str(i))
            p = p.replace('#2#',str(j))
            p = p.replace('#3#',str(i*10+j))
            print p
            
def doSub3(all_the_text):
    print "----in doSub3()"
    for i in range(1,13):
      for j in range(6,23):
        print "----"
        p = all_the_text
        p = p.replace('#indust_id#',str(i))
        p = p.replace('#region_id#',str(j))
        print p

def doSub4(all_the_text):
    print "----in doSub4()"
#    for i in range(1,13):
#        for j in range(6,23):
#            p = all_the_text
#            p = p.replace('#indust_id#',str(i))
#            p = p.replace('#region_id#',str(j))
#            for k in range(19):
#                kk = k + 10300
#                print "----"
#                p1 = p
#                p1 = p1.replace('#dept_role_id#',str(kk))
#                p1 = p1.replace('#type#','1')
#                p1 = p1.replace('#memo#','i='+str(i)+' j='+str(j)+' kk='+str(kk))
#                print p1
    for i in range(100):
        p = all_the_text
        p = p.replace('#indust_id#','3')
        p = p.replace('#region_id#','6')
        p = p.replace('#dept_role_id#','102877')
        p = p.replace('#type#','0')
        p = p.replace('#memo#','i='+str(i))
        print p
        
def doSub5(all_the_text):
    print "----in doSub5()"
    for i in range(1,24):
        print "----"
        p = all_the_text
        p = p.replace('#supplier_name#',"'supplier_name"+str(i)+"'")
        print p


def doSub6(all_the_text):
    print "----in doSub6()"
    num = 24
    for i in range(1,num+1):
        print "----"
        p = all_the_text
        p = p.replace('#record_type#','record_type'+str(i))
        print p

def doSub7(all_the_text):
    print "----in doSub7()"
    num = 24
    for i in range(1,num+1):
        print "----"
        p = all_the_text
        p = p.replace('#record_type_id#',str(i))
        for j in range(1,num+1):
            p2 = p
            p2 = p2.replace('#record_content#','record_content'+str(j))
            p2 = p2.replace('#attachment#','attachment'+str(j))
            print p
        
def doSub8(all_the_text):
    print "----in doSub8()"
    num = 47
    for i in range(4,num+1):
        print "----"
        p = all_the_text
        p = p.replace('#name#','RiskMeasure1024'+str(i))
        p = p.replace('#title#','#RiskMeasure1024#'+str(i))
        print p


if __name__ == "__main__":
    main()
